package com.yanghui.lingyue.functions.timer

import com.yanghui.lingyue.bot.Bot
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

object TimeScheduler {

    /**
     * 按照每个分钟刷新一次的原则，一分钟执行一次动作
     */
    val taskMap: LinkedHashMap<String, suspend (String) -> Unit> = LinkedHashMap()

    fun start() {
        Bot.sikaCore.schedule(60000) {
            taskMap.forEach { (_, v) ->
                GlobalScope.launch(Dispatchers.Default) {
                    v(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm")))
                }
            }
        }
    }

}